window.onload = function () {
  $('.navigation li').eq(0).addClass('active')
}

$('.js_sreach_btn').on('click', function () {
  var val = $('input[name="sreach_input"]').val()
  window.location.href = '../News/sreach.html?search=' + val
})

$('#js_sreach_box').on('keyup', function (e) {
  if (e.keyCode == 13) {
    var val = $('input[name="sreach_input"]').val()
    window.location.href = '../News/sreach.html?search=' + val
  }
})

$('.tab-item li').on('click', function () {
  var idx = $(this).index()
  $(this).addClass('active').siblings().removeClass('active')
  $('.tab-box').eq(idx).addClass('active').siblings().removeClass('active')
})

// 首页数据
$.ajax({
  url: 'http://221.10.2.222:5680/api/w1/news/GetNewsByCondition',
  type: "GET",
  dataType: "json",
  success: function (res) {
    console.log(res)
    var banner = template('banner_tpl', res)

    var notice = template('notice_tpl', res)
    $('#banner_html').html(banner)

    $('#notice_html').html(notice)
    var mySwiper = new Swiper('.swiper-container', {
      loop: true,
      autoplay: 4000,
      pagination: '.pagination',
    });
  },
  error: function (e) {}
})

// 新闻
$.ajax({
  url: 'http://221.10.2.222:5680/api/ow/news/list',
  type: "GET",
  dataType: "json",
  data: {
    type: 1,
    page: 1,
    keyword: ' ',
    pagesize: 8
  },
  success: function (res) {
    res.resultdata = JSON.parse(res.resultdata)
    var news = template('news_tpl', res)
    $('#news_html').html(news)
  }
})

// 金点子
$.ajax({
  url: 'http://221.10.2.222:5680/api/w1/GoldenIdea/getWebList',
  type: "POST",
  dataType: "json",
  data: {
    PageIndex: 1,
    isHome: true
  },
  success: function (res) {
    var item = template('rolltext_tpl', res)
    $('#rolltext').html(item)
    $("#rolltext").powerSlider({
      delayTime: 3000
    });
  }
})

// 办事流程
$.ajax({
  url: 'http://221.10.2.222:5680/api/ow/news/list',
  type: "GET",
  dataType: "json",
  data: {
    page: 1,
    type: 5,
    keyword: '',
    pagesize: 6
  },
  success: function (res) {
    res.resultdata = JSON.parse(res.resultdata)
    var guide = template('guide_tpl', res)
    $('#guide_html').html(guide)
  }
})

$.ajax({
  url: 'http://221.10.2.222:5680/api/ow/news/list',
  type: "GET",
  dataType: "json",
  data: {
    page: 1,
    type: 4,
    keyword: '',
    pagesize: 6
  },
  success: function (res) {
    res.resultdata = JSON.parse(res.resultdata)
    var guide = template('guide_tpl_2', res)
    $('#guide_html_2').html(guide)
  }
})

template.defaults.imports._appealtype = function (val) {
  var arr = ['投诉', '监督', '举报', '曝光', '表扬', '建议', '其他', '咨询']
  val = parseInt(val) - 1
  return arr[val] ? arr[val] : '其他'
};

template.defaults.imports._status = function (val) {
  var arr = ['待处理', '待审核', '处理中', '待评价', '已完结', '已取消', '网格化管理员待处理', '网格化管理员已处理', '审核失败']

  if (val == 1 || val == 2 || val == 3 || val == 7) {
    return '办理中'
  } else {
    return '已办结'
  }
};

template.defaults.imports._source = function (val) {
  var arr = ['热线', 'APP', '官网', '微信', '书记信箱', '区长信箱', '市12345', '地方领导留言板', '微博']
  val = parseInt(val) - 1
  return arr[val] ? arr[val] : '其他'
};

template.defaults.imports._score = function (val) {
  var arr = [, '不满意', '满意', '满意', '满意', '非常满意']
  val = parseInt(val) - 1
  return arr[val] ? arr[val] : '未评价'
};

$.ajax({
  url: 'http://221.10.2.222:5680/api/ow/Complain/Far/List/?ispublic=1&page=1&pagesize=16',
  type: "GET",
  dataType: "json",
  success: function (res) {
    res.resultdata = JSON.parse(res.resultdata)
    console.log(res)
    var table = template('table_tpl', res)
    $('#table_html').html(table)
  },
  error: function (e) {}
})